package speculoos.jndi.pool;

import javax.naming.directory.DirContext;

/**
 * Interface defining simple contract for connection creation.
 * <p>
 * This simple connection factory interface delegates creation and 
 * deletion of DirContext objects to some ohter 
 * </p>
 * @author nono
 * @version $Id: ConnectionFactory.java 259 2006-05-23 10:34:50Z /C=FR/ST=Nord/L=Lille/O=Norsys SA/OU=UE/CN=Arnaud Bailly/emailAddress=abailly@norsys.fr $
 */
public interface ConnectionFactory {

	/**
	 * Creates a new context - ie. connection - using the 
	 * given environment.
	 * 
	 * @return an instance of DirContext. May be null if 
	 * connection is unavailable (eg. Maximum connectionx threshold
	 * has been reached)
	 * @throws Exception
	 */
	DirContext connect() throws Exception;

	/**
	 * Disconnect a context from underlying system.
	 * 
	 * @param ctx the context to close.
	 * @throws Exception
	 */
	void disconnect(DirContext ctx) throws Exception;

	/**
	 * Sets the maximum simulatneous connections this 
	 * factory should handle. 
	 * Any further attempt to connect should result 
	 * in connect return null.
	 * 
	 * @param maxPoolSize
	 */
	void setMaximumConnection(int maxPoolSize);

}